package xiong.rbac.view;

import java.util.Scanner;

public class MainView {

    public static final String MENU = """
            --------------
                RBAC系统
            --------------
            |  0 退出系统  |
            |  1 部门管理  |
            |  2 角色管理  |
            |  3 用户管理  |
            --------------
            请输入编号:""";
    ;

    public static Scanner input;

    static {
        input = new Scanner(System.in);
    }

    private final DeptView deptView;
    private final UserView roleView;
    private final UserView userView;

    private static MainView singleton;

    public static MainView getInstance() {
        if (singleton == null) {
            singleton = new MainView();
        }
        return singleton;
    }

    private MainView() {
        deptView = DeptView.getInstance();
        roleView = UserView.getInstance();
        userView = UserView.getInstance();
    }

    public void show() {
        String menuChoice;
        do {
            System.out.println(MENU);
            menuChoice = input.nextLine();
            switch (menuChoice) {
                case "0" -> System.out.println("成功退出系统,欢迎再次使用");
                case "1" -> deptView.show();
                // T0D0  显示部门管理界面
                case "2" -> roleView.show();
                // T0D0  显示角色管理界面
                case "3" -> userView.show();
                // T0D0  显示用户管理界面
                default -> System.out.println("输入错误,请重新输入");
            }
        } while (!"0".equals(menuChoice));
        input.close();
    }
}
